package com.liuh.fram.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.liuh.fram.err.LocalException;
import com.liuh.fram.err.LocalException.ErrorType;

/**
 * @note 接口拦截器处理
 * @author liuh
 * */
public class ApiClientInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation ai) {
		Controller c = ai.getController();
		String key = c.getRequest().getHeader("keya");
		key = StrKit.isBlank(c.getRequest().getHeader("keya")) ? "" : key;
		if (PropKit.get("local_keya").equals(key)) {
			ai.invoke();
		} else {
			// 无权限访问api
			throw new LocalException(ErrorType.apiNoAuth);
		}
	}
}